﻿using Simple.Framework.Protocol;
using SimpleNet.Handle;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/*********************************************************
 * 命名空间 Simple.PrettyNet.Protocol
 * 接口名称  IMDTDataPackProtocol
 * 开发人员：zdm
 * 创建时间：2023/11/23 15:13:45
 * 描述说明：
 * 更改历史：
 * 
 * *******************************************************/
namespace SimpleNet.Protocol
{
	public interface IMDTDataPackProtocol
	{
		/// <summary>
		/// 初始化一个包
		/// </summary>
		/// <param name="len"></param>
		/// <param name="commandId"></param>
		/// <param name="packStatus"></param>
		/// <returns></returns>
		/// <exception cref="ArgumentException"></exception>
		public byte[] InitializeDataPack(int len, int commandId, ePackStatus packStatus);

		#region reply
		/// <summary>
		/// login
		/// </summary>
		/// <param name="commandId"></param>
		/// <param name="ReceivePackType"></param>
		/// <param name="IpAddress"></param>
		/// <param name="Port"></param>
		/// <param name="updateflag"></param>
		/// <returns></returns>
		public byte[] LoginReply(int commandId, ePackStatus ReceivePackType, string IpAddress, int Port, int updateflag = 0);

		/// <summary>
		/// heart
		/// </summary>
		/// <param name="CommandStatus"></param>
		/// <param name="commandId"></param>
		/// <returns></returns>
		public byte[] HeartReply(int commandId, ePackStatus ReceivePackType);


		/// <summary>
		/// 
		/// </summary>
		/// <param name="commandId"></param>
		/// <param name="ReceivePackType"></param>
		/// <param name="json"></param>
		/// <returns></returns>
		public byte[] ReceiveDeviceInfoReply(int commandId, ePackStatus ReceivePackType, string json);


		/// <summary>
		/// 
		/// </summary>
		/// <param name="commandId"></param>
		/// <param name="ReceivePackType"></param>
		/// <param name="totalSize"></param>
		/// <param name="totalPackNum"></param>
		/// <param name="firmwareVersion"></param>
		/// <returns></returns>
		public byte[] VersionUpgradeReply(int commandId, ePackStatus ReceivePackType, int totalSize, int totalPackNum, string firmwareVersion);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="commandId"></param>
		/// <param name="ReceivePackType"></param>
		/// <param name="firmwareVersion"></param>
		/// <param name="totalPackNum"></param>
		/// <param name="currentPackNum"></param>
		/// <param name="currentPackDataLength"></param>
		/// <param name="currentPackData"></param>
		/// <returns></returns>
		public byte[] VersionUpgradeDataReply(int commandId, ePackStatus ReceivePackType, string firmwareVersion, int totalPackNum, int currentPackNum, int currentPackDataLength, byte[] currentPackData);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="commandId"></param>
		/// <param name="ReceivePackType"></param>
		/// <returns></returns>
		public byte[] ErrorReply(int commandId, ePackStatus ReceivePackType);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="ReceivePackType"></param>
		/// <returns></returns>
		public byte[] ErrorReply(ePackStatus ReceivePackType);



		public bool CheckHeadAndTail(IContext context);


		public bool CheckHead(IContext context);


		public bool CheckTail(IContext context);

		/// <summary>
		/// 
		/// </summary>
		/// <param name="context"></param>
		/// <returns></returns>
		public bool CalculateChecksum(IContext context);
		
		#endregion
		/// <summary>
		/// 完成 crc 计算
		/// </summary>
		/// <param name="buffer"></param>
		public void CompletePackCRC(byte[] buffer);
		/// <summary>
		/// 
		/// </summary>
		/// <typeparam name="TProtocol"></typeparam>
		/// <param name="tProtocol"></param>
		/// <returns></returns>

		public TProtocol GetProtocol<TProtocol>() where TProtocol : MDTDataPackProtocol;

		/// <summary>
		/// 
		/// </summary>
		/// <param name="data"></param>
		/// <param name="commandId"></param>
		/// <returns></returns>
		public byte[] GetServerToClientData<TData>(TData data, ref long commandId);

	}
}
